package com.changgou.user.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.HashSet;

//swagger的基本配置
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

    @Bean
    public Docket createRestApi() {
        HashSet<String> strings = new HashSet<>();
        strings.add("application/json");
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("user-group")//用户组
                .produces(strings)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.changgou.user"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                //设置标题
                .title("畅购后台RESTful APIs接口文档")

                .description("畅购swagger-bootstrap-ui在线接口文档")
                //访问地址
                .termsOfServiceUrl("http://localhost:8999/")
                //联系人
                .contact("developer@mail.com")
                //版本
                .version("1.0")
                //构建
                .build();
    }
}